function isUndefined(variable)
{
	return typeof variable=='undefined'?true:false;
}

function strlen(str)
{
	var ie;
	return(ie&&str.indexOf('\n')!=-1)?str.replace(/\r?\n/g,'_').length:str.length;
}

function trim(str)
{
	var re=/\s*(\S[^\0]*\S)\s*/;
	re.exec(str);
	return RegExp.$1;
}

//返回一个UNIX时间戳，和PHP一样的
function time()
{
	var _dateObj=new Date();
	var _time=_dateObj.getTime().toString();
	return parseInt(_time.substring(0,_time.length-3));
}
//JS缓存类，用于缓存AJAX返回结果非常有用
function CacheHandler()
{
	this.data={};
	this.lifeTime=3600;//默认缓存一小时
	this.setLifeTime=function(lifeTime)
	{
		this.lifeTime=lifeTime;
	};
	this.save=function (name,value,lifeTime)
	{
		this.data[name]={expire:time()+(parseInt(lifeTime) || this.lifeTime),value:value};
		return this.data[name]['value'];
	};
	this.get=function (name)
	{
		if(this.data[name]==undefined || this.data[name]['expire']<time())return undefined;
		return this.data[name]['value'];
	};
	this.getOrSave=function(name,value,lifeTime)
	{
		return this.get(name)==undefined && this.save(name,value,lifeTime);
	};
	this.clear=function (name)
	{
		name?delete this.data[name]:this.data={};
	};
}
var Cache=new CacheHandler();//实例化个全局缓存对象

//
function headDoSearch()
{
	var searchValue=$('#headq').val();
	var searchType=$('#headSearchType').val();
	var redirectURL='';
	if(''==searchValue||'undefined'==searchValue||'请输入关键字'==searchValue)
	{
		alert("请输入关键字");
	}
	else
	{
		if('userSearch'==searchType){
			redirectURL='index.php?mod=search&code=user&nickname='+searchValue;
		}else if('tagSearch'==searchType){
			redirectURL='index.php?mod=search&code=tag&tag='+searchValue;
		}else if('topicSearch'==searchType){
			redirectURL='index.php?mod=search&code=topic&topic='+searchValue;
		}else if('voteSearch'==searchType){
			//加入对投票的search	By ~ZZ~ 2010-04-22
			redirectURL='index.php?mod=search&code=vote&q='+searchValue;
		}else if('qunSearch'==searchType){
			//加入对微群的search	By ~ZZ~ 2010-08-23
			redirectURL='index.php?mod=search&code=qun&q='+searchValue;
		}else{
			alert("未定义的操作");
		}

		if(''!=redirectURL)
		{
			window.location.href=thisSiteURL+redirectURL;
		}
	}
	return false;
}

/**
 * 检查字符串是否是json代码
 */
function is_json(data)
{
	var reg = new RegExp(/^{.*}$/igm);
	if (data.search(reg) != -1) {
		return true;
	}
	return false;
}

/**
 * 动态加载js
 */
function loadJs(file)
{
	var head = $('head');
    $("<scri"+"pt>"+"</scr"+"ipt>").attr({src:file,type:'text/javascript',id:'load'}).appendTo(head);
}
